import { Component, OnInit, OnDestroy } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Subscription, Observable } from 'rxjs';
import { DialogService } from 'app/shared/dialog';
import { HttpClient } from '@angular/common/http';
import { ToolsService } from 'app/shared/service';

@Component({
    selector: 'itmp-home',
    templateUrl: './home.component.html',
    styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit, OnDestroy {
    test2 = '';
    subscriptions: Array<Subscription> = [];
    map: any;
    constructor(private translate: TranslateService, private dialog: DialogService, private http: HttpClient, private tools: ToolsService) {
        // const url += '/content/data/CCTV.json';
        // this.http.get('')
        // this.getFeatureData();
    }

    comfirm() {
        this.dialog
            .confirm({ title: 'Home.Home.Delete_Confirm', content: '是否删除', buttonOkTxt: 'Save', buttonCancelTxt: 'Cancel' })
            .subscribe(res => {});
    }

    ngOnInit() {
        let transSub;
        this.translate.get('Home.Home.Test2').subscribe(res => {
            // this.test = res
            // do something
            this.test2 = res;
        });
        transSub = this.translate.onLangChange.subscribe((res: any) => {
            // do something
            if (!res) {
                return;
            }
            this.test2 = res.translations.Home.Home.Test2;
        });

        this.subscriptions.push(transSub);
    }

    ngOnDestroy() {
        this.subscriptions.forEach(sub => {
            if (sub) {
                sub.unsubscribe();
            }
        });
    }
}
